package com.ruoyi.web.controller.snmp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SnmpDeviceinfo;
import com.ruoyi.system.service.ISnmpDeviceinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/snmp/deviceinfo")
public class SnmpDeviceinfoController extends BaseController
{
    @Autowired
    private ISnmpDeviceinfoService snmpDeviceinfoService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnmpDeviceinfo snmpDeviceinfo)
    {
        startPage();
        List<SnmpDeviceinfo> list = snmpDeviceinfoService.selectSnmpDeviceinfoList(snmpDeviceinfo);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:list')")
    @GetMapping("/alllist")
    public AjaxResult alllist()
    {
        List<SnmpDeviceinfo> list = snmpDeviceinfoService.selectSnmpDeviceinfoList(null);
        return success(list);
    }
    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnmpDeviceinfo snmpDeviceinfo)
    {
        List<SnmpDeviceinfo> list = snmpDeviceinfoService.selectSnmpDeviceinfoList(snmpDeviceinfo);
        ExcelUtil<SnmpDeviceinfo> util = new ExcelUtil<SnmpDeviceinfo>(SnmpDeviceinfo.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") String deviceId)
    {
        return success(snmpDeviceinfoService.selectSnmpDeviceinfoByDeviceId(deviceId));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnmpDeviceinfo snmpDeviceinfo)
    {
        return toAjax(snmpDeviceinfoService.insertSnmpDeviceinfo(snmpDeviceinfo));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnmpDeviceinfo snmpDeviceinfo)
    {
        return toAjax(snmpDeviceinfoService.updateSnmpDeviceinfo(snmpDeviceinfo));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('snmp:deviceinfo:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable String[] deviceIds)
    {
        return toAjax(snmpDeviceinfoService.deleteSnmpDeviceinfoByDeviceIds(deviceIds));
    }
}
